package inc
{
	import flash.net.SharedObject;
	
	import mx.controls.Alert;
	
	public class ShareData
	{
		public function ShareData()
		{
		}
		
		public static var PROJECT:String = "lottery";
		public static var USER_ID:String = "userId";
		public static var USER_NAME:String = "username";
		public static var USER_LINK:String = "userlink";
		public static var USER_BALANCE:String = "userBalance";
		public static var LOTTERY_ID:String = "lotteryId";
		public static var LOTTERY_NAME:String = "lotteryName";

		public static function write(name:String, value:String):void{
			var share:SharedObject = SharedObject.getLocal(PROJECT, "/");
			share.data[name] = value;
		}
		
		public static function read(name:String):String{
			var share:SharedObject = SharedObject.getLocal(PROJECT, "/");
			if(share.data[name]){
				return share.data[name];
			}
			return null;
		}
		
		//添加属性
		public static function addData(name:String, value:String):void{
			var share:SharedObject = SharedObject.getLocal(PROJECT, "/");
			switch(name){
				case USER_ID:share.data.userId = value;break;
				case USER_NAME:share.data.username = value;break;
				case USER_LINK:share.data.userlink = value;break;
				case USER_BALANCE:share.data.userBalance = value;break;
				case LOTTERY_ID:share.data.lotteryId = value;break;
				case LOTTERY_NAME:share.data.lotteryName = value;break;
				default:Alert.show("inc.ShareData.addData()=>未指定的属性名称:"+name);
			}
			//Alert.show("addData()");
		}
		
		//获取属性
		public static function getData(name:String):String{
			var share:SharedObject = SharedObject.getLocal(PROJECT, "/");
			switch(name){
				case USER_ID:return share.data.userId;break;
				case USER_NAME:return share.data.username;break;
				case USER_LINK:return share.data.userlink;break;
				case USER_BALANCE:return share.data.userBalance;break;
				case LOTTERY_ID:return share.data.lotteryId;break;
				case LOTTERY_NAME:return share.data.lotteryName;break;
				default:Alert.show("inc.ShareData.getData()=>未指定的属性名称:"+name);
				return null;
			}
		}
		
		//是否是快捷投注
		public static function isQuickBet():Boolean{
			var share:SharedObject = SharedObject.getLocal(PROJECT, "/");
			if(share.data.quickBet != null && share.data.quickBet==1){
				share.data.quickBet = 0;
				return true;
			}
			return false;
		}
		
		
	}
}